//
//  FQDBaseInfoViewController.m
//  FakeQDaily
//
//  Created by mewxiv on 9/9/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDBaseInfoViewController.h"
#import "FQDNavigationView.h"

#import "Masonry.h"

@interface FQDBaseInfoViewController ()

// 模糊背景图
@property (nonatomic, strong) UIImageView *bgImageView;
// 背景点击事件
@property (nonatomic, strong) UITapGestureRecognizer *backgroundTap;

@end

@implementation FQDBaseInfoViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupBackground];
}

- (void)setupBackground
{
    self.bgImageView = [[UIImageView alloc] init];
    self.bgImageView.image = self.blurBgImage;
    [self.view addSubview:self.bgImageView];
    
    WeakSelf;
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.view);
    }];
    
    UIView *maskView = [[UIView alloc] initWithFrame:self.bgImageView.bounds];
    maskView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    maskView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.65f];
    [self.bgImageView addSubview:maskView];
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

#pragma mark - Event Response
- (void)popBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Gesture Recognizers
- (void)backgroundTapped:(UIGestureRecognizer *)gr
{
    [self.view endEditing:YES];
}

#pragma mark - Getters and Setters
- (FQDNavigationView *)navView
{
    if (!_navView) {
        CGRect navFrame = CGRectMake(0, 0, 320.0f, 64.0f);
        _navView = [[FQDNavigationView alloc] initWithFrame:navFrame];
        [self.view addSubview:_navView];

        [self.navView.backButton addTarget:self action:@selector(popBack:) forControlEvents:UIControlEventTouchUpInside];

        WeakSelf;
        [_navView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.and.right.equalTo(weakSelf.view);
            make.height.equalTo(@64);
        }];
    }
    return _navView;
}

- (void)setBlurBgImage:(UIImage *)blurBgImage
{
    _blurBgImage = blurBgImage;
    self.bgImageView.image = blurBgImage;
}

- (void)setHideKeyboardOnTap:(BOOL)hideKeyboardOnTap
{
    _hideKeyboardOnTap = hideKeyboardOnTap;
    self.backgroundTap.enabled = hideKeyboardOnTap;
}

- (UITapGestureRecognizer *)backgroundTap
{
    if (!_backgroundTap) {
        _backgroundTap = [[UITapGestureRecognizer alloc] initWithTarget:self
                          action:@selector(backgroundTapped:)];
        _backgroundTap.enabled = NO;
        [self.view addGestureRecognizer:_backgroundTap];
    }
    return _backgroundTap;
}

@end
